{{ template "layout/adminheader" .}}
<main id="body">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive arrlist">
                            <table class="table" style="min-width: 800px">
                                <thead>
                                <tr align="center">
                                    <th width="150">版块 ID</th>
                                    <th width="80" class="text-center">图标</th>
                                    {{/*<th width="130"></th>*/}}
                                    <th >名称</th>
                                    <th width="100">排序</th>
                                    <th width="100" class="text-center">编辑</th>
                                    <th width="100" class="text-center">删除</th>
                                </tr>
                                </thead><thead>
                                </thead><tbody>
                                {{range .forums}}
                                <tr align="center" rowid="{{.ID}}">
                                    <td class="50">{{.ID}}</td>
                                    <td align="left">
                                        <img src="{{.Icon}}" class="forum" width="48" id="img_1">
                                    </td>

                                    <td>{{.Name}}</td>
                                    <td>{{.Rank}}</td>
                                    <td><button onclick="editforum(this, {{.ID}})" class="btn row_edit" role="button" tabindex="0">编辑</button></td>
                                    <td><button onclick="deleteforum(this, {{.ID}})" class="btn row_delete" role="button" tabindex="0">删除</button></td>
                                </tr>
                                {{end}}

                                </tbody>
                            </table>
                        </div>
                        <p class="text-center">
                            <a href="/admin/forum_new.html" id="adminaddforum">
                                <button type="button" class="btn btn-primary"  data-loading-text="正在提交..." style="width: 10rem;">新增模块 +</button>
                            </a>
                        </p>
                        <p class="small text-grey">注：请谨慎编辑版块，一旦确定后不要轻易变动，否则可能会导致数据关联错误，一般在正式运营时就不要再变动。</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<script>
    function getfile(ele) {
        var fileString
        files = $(ele).prop('files')
        var reader = new FileReader();//新建一个FileReader
        reader.readAsText(files[0], "UTF-8");//读取文件
        reader.onload = function(evt){ //读取完文件之后会回来这里
            fileString = evt.target.result;
        }
        return fileString
    }

    //if(!debug) $.alert('请谨慎编辑版块，一旦确定后不要轻易变动，否则可能会导致数据关联错误，一般在正式运营时就不要再变动。');
    var maxfid = {{.fnum}};

    var jform = $("#form");
    var jsubmit = $("#submit");

    // jform.base64_encode_file(); // 对文件进行 base64 编码，处理文件上传，很方便

    jsubmit.on('click', function(){
        jform.reset();
        var postdata = {'forums': pickFormData()};
        // var postdata = {"Forums": ["123"]};
        console.log(postdata);
        jsubmit.button('loading');

        $.ajax({
            type: "post",
            url: jform.attr('action'),
            dataType: "json",
            contentType:'application/json; charset=utf-8',
            data: {
                'forums':[
                    {
                        "forum_id":"1",
                        "forum_icon":"sdfsdf",
                        "forum_name":"sdfsdf",
                        "forum_rank":"1"
                    }
                ]
            },
            success: function(data){
                console.log(data)
            }
        });
        return false;
    });

    // 删除
    function deleteforum(elem, fid) {
        $.confirm("确定删除主题id:" + fid, function () {
            $.ajax({
                type: "post",
                url: "/admin/forum/delete?token="+admintoken,
                data: {
                    'forumid':fid
                },
                success: function(res){
                    if (res.code == 200) {
                        $.alert("删除成功")
                        setTimeout(function () {
                            location.reload()
                        }, 2000)
                    }
                }
            });
        })
    }

    // 删除跳转
    function editforum(elem, fid) {
        location = "/admin/forum/edit.html?id="+fid+"&token="+admintoken
    }
</script>
{{ template "layout/adminfooter" .}}